package classroom;

import java.util.Objects;

public abstract class People implements CanAsk, Answerable {
    protected int age;
    protected String name;
    protected String words;
    protected String action;

    public People(int age, String name, String words, String action) {
        this.age = age;
        this.name = name;
        this.words = words;
        this.action = action;
    }

    // 每个人可以做些什么
    public final void doSomething() {
        String action = action();
        String words = words();
        int len = Math.max(action.length(), words.length()) * 2;
        StringBuilder sb = new StringBuilder();
        String line;
        for (int i = 0; i < len / 2; i++) {
            sb.append("=");
        }
        sb.append(name).append("的分割线");
        for (int i = 0; i < len / 2; i++) {
            sb.append("=");
        }

        line = sb.toString();
        System.out.println(line);
        System.out.println(action);
        System.out.print("然后说：\"");
        System.out.print(words);
        System.out.println("。\"");
        System.out.println(line);
    }

    // 将会说出的一段话。e.g 我是杨晨
    protected abstract String words();

    // 做出一个动作。e.g 露出开心的笑容
    protected abstract String action();

    //为了Set可以更好的判断people是否相同，重写Object类的equals和hashCode函数
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        People people = (People) o;
        return age == people.age &&
                Objects.equals(name, people.name) &&
                Objects.equals(words, people.words) &&
                Objects.equals(action, people.action);
    }

    @Override
    public int hashCode() {
        return Objects.hash(age, name, words, action);
    }
}
